/***************************************************************************
                          pascal.l  -  Reglas de Pascal--
                             -------------------
    copyright            : (C) 2002 by Duncan Mac-Vicar P.
    email                : duncan@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   * 
 *                                                                         *
 ***************************************************************************/

%{
#include "codigos.h"
#include "hash.h"
#include "bi.h"
#include "y.tab.h"
#define TAB_WIDTH 8
extern int fila;
extern int columna;

extern int sub_code;


%}
LETRA [A-Za-z]
DIGITO [0-9]
NOCLOSECOMMENT1 [^}]
NOCLOSECOMMENT2 [^("*"")")]
NOOPENCOMMENT1 [^{]
NOOPENCOMMENT2 [^("(""*")]
NEWLINE [\n]
CARRIAGERETURN [\r]
TABULATOR [\t]
IDENTIFIER [a-z][a-z0-9]*
%%
"{"({NOCLOSECOMMENT1})*"}" {    int curr_char;
                                for ( curr_char = 0 ; curr_char < yyleng ; curr_char++ )
								{
									switch(yytext[curr_char])
									{
										case '\n':
                                   		fila++;
										columna=0;
										break;
										
										case '\t':
										columna = columna + TAB_WIDTH;
										break;
				
										default:
                                        columna++;
										break;

									}
								}

                        	}
"(*"({NOCLOSECOMMENT2})*"*)" {    int curr_char;
                                for ( curr_char = 0 ; curr_char < yyleng ; curr_char++ )
								{
									switch(yytext[curr_char])
									{
										case '\n':
                                   		fila++;
										columna = 0;
										break;
										
										case '\t':
										columna = columna + TAB_WIDTH;
										break;
				
										default:
                                        columna++;
										break;

									}
								}

                        	}
program { columna = columna + yyleng; return PROGRAM; }
begin { columna = columna + yyleng; return BEG; }
end  { columna = columna + yyleng; return END; }
var  { columna = columna + yyleng; return VAR; }
record  { columna = columna + yyleng; return RECORD; }
procedure  { columna = columna + yyleng; return PROCEDURE; }
integer  { columna = columna + yyleng; return INTEGER; }
boolean  { columna = columna + yyleng; return BOOLEAN; }
const  { columna = columna + yyleng; return CONST; }

of  { columna = columna + yyleng; return OF; }
type  { columna = columna + yyleng; return TYPE; }
":="  { columna = columna + yyleng; return ASSIGN; }
if	{ columna = columna + yyleng; sub_code = COND_IF; return CONDITIONAL; }
then { columna = columna + yyleng; sub_code = COND_THEN; return CONDITIONAL; }
else { columna = columna + yyleng; sub_code = COND_ELSE; return CONDITIONAL; }
while	{ columna = columna + yyleng; sub_code = WHILE; return BUCLES; }
do { columna = columna + yyleng; sub_code = DO; return BUCLES; }
loop { columna = columna + yyleng; sub_code = LOOP; return BUCLES; }
"+"  { columna = columna + yyleng; sub_code = OP_ADD_PLUS; return OP_ADD; }
"-"  { columna = columna + yyleng; sub_code = OP_ADD_MINUS; return OP_ADD; }
or  { columna = columna + yyleng; sub_code = OP_ADD_OR; return OP_ADD; }

and  { columna = columna + yyleng; sub_code = OP_MUL_AND; return OP_MUL; }
"*"  { columna = columna + yyleng; sub_code = OP_MUL_AST; return OP_MUL; }
mod  { columna = columna + yyleng; sub_code = OP_MUL_MOD; return OP_MUL; }
div  { columna = columna + yyleng; sub_code = OP_MUL_DIV; return OP_MUL; }
not  { columna = columna + yyleng; sub_code = OP_MUL_NOT; return OP_MUL; }

"true"  { columna = columna + yyleng; sub_code = B_TRUE; return BOOL; }
"false"  { columna = columna + yyleng; sub_code = B_FALSE; return BOOL; }


"<>"  { columna = columna + yyleng; sub_code = OP_REL_NOTEQUAL; return OP_REL; }
">="  { columna = columna + yyleng; sub_code = OP_REL_MAJOREQ; return OP_REL; }
">"  { columna = columna + yyleng; sub_code = OP_REL_MAJOR; return OP_REL; }
"<="  { columna = columna + yyleng; sub_code = OP_REL_MINOREQ; return OP_REL; }
"<"  { columna = columna + yyleng; sub_code = OP_REL_MINOR; return OP_REL; }
"="  { columna = columna + yyleng; sub_code = OP_REL_EQUAL; return OP_REL; }
";"  { columna = columna + yyleng; sub_code = SEMICOLON; return PUNCTUATION; }
","  { columna = columna + yyleng; sub_code = COMMA; return PUNCTUATION; }
":"  { columna = columna + yyleng; sub_code = COLON; return PUNCTUATION; }
"("  { columna = columna + yyleng; sub_code = ROUNDOPEN; return PUNCTUATION; }
")"  { columna = columna + yyleng; sub_code = ROUNDCLOSE; return PUNCTUATION; }
".."  { columna = columna + yyleng; sub_code = DOUBLEPOINT; return PUNCTUATION; }
"."  { columna = columna + yyleng; sub_code = POINT; return PUNCTUATION; }

{IDENTIFIER} { columna = columna + yyleng; return ID; }
{DIGITO}+	{ columna = columna + yyleng; return INT; }
[ ]		{ columna++; /* espacios */ }
{NEWLINE} { fila++; columna=0;}
{CARRIAGERETURN} ;
{TABULATOR} { fila = fila + TAB_WIDTH;}
. { columna = columna + yyleng; return UNKNOWN;}





